import request from '@/utils/request'

// 数据格式
const headers = {'Content-Type': 'application/x-www-form-urlencoded'};


// 请求头添加Authorization Basic client_id:client_secret
const auth = {
    // cloent_id
    username: 'mxg-blog-admin',
    // client_secret
    password: '123456'
};

export function login(data) {
    return request({
        headers,
        auth,
        url: '/auth/login',
        method: 'post',
        params: data

    });
}

export function getXieyi() {
    console.log(window.location.href);
    return request({
        url: `${window.location.href}/xieyi.html`,
        method: "get"
    });
}

// 查询用户名是否已经被注册
export function getUserByUsername(username) {
    return request({
        url: `/system/api/user/username/${username}`,
        method: "get"
    });
}

// 提交数据
export function register(data) {
    return request({
        headers,
        auth,
        url: `/system/api/user/register`,
        method: "post",
        params: data
    })
}

// 推出系统
export function logout(accessToken) {
    return request({
        url: `/auth/logout`,
        method: "get",
        params: {
            accessToken
        }
    });

}

// 刷新令牌接口
export function refreshToken(refreshToken) {
    return request({
        headers,
        auth,
        url: `/auth/user/refreshToken`,
        method: 'get',
        params: refreshToken
    });

}
